/*
 * StatusValueDisplay.java
 *
 * Created on 13 March 2004, 01:53
 * Copyright (C) 2004, Velocityme Partnership
 */

package com.velocityme.client.gui.node.status;

import com.velocityme.valueobjects.NodeValue;
import com.velocityme.valueobjects.StatusValue;

/**
 *
 * @author  Robert
 */
public class StatusValueDisplay extends javax.swing.JPanel {
    
    private StatusValue m_statusValue;

    /** Creates new form StatusValueDisplay */
    public StatusValueDisplay(StatusValue p_statusValue) {
        initComponents();
        setStatusValue(p_statusValue);
    }
    
    public void setStatusValue(StatusValue p_statusValue) {
        NodeValue nodeValue = p_statusValue.getNodeValue();
        if (nodeValue != null) {
            if (nodeValue.nameHasBeenSet())
                jTextFieldName.setText(nodeValue.getName());
            if (nodeValue.descriptionHasBeenSet())
                jTextAreaDescription.setText(nodeValue.getDescription());
        }
        m_statusValue = p_statusValue;
    }
    
    public StatusValue getStatusValue() {
        if (m_statusValue.getNodeValue() == null)
            m_statusValue.setNodeValue(new NodeValue());
        m_statusValue.getNodeValue().setName(jTextFieldName.getText());
        m_statusValue.getNodeValue().setDescription(jTextAreaDescription.getText());
        return m_statusValue;
    }
    
    public void setEditable(boolean p_editable) {
        jTextFieldName.setEditable(p_editable);
        jTextAreaDescription.setEditable(p_editable);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jLabelIcon = new javax.swing.JLabel();
        jLabelName = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        jLabelDescription = new javax.swing.JLabel();
        jScrollPaneDescription = new javax.swing.JScrollPane();
        jTextAreaDescription = new javax.swing.JTextArea();

        setLayout(new java.awt.GridBagLayout());

        jLabelIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/velocityme/client/icons/status-32x32.png")));
        add(jLabelIcon, new java.awt.GridBagConstraints());

        jLabelName.setText("Name:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jLabelName, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jTextFieldName, gridBagConstraints);

        jLabelDescription.setText("Description:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jLabelDescription, gridBagConstraints);

        jScrollPaneDescription.setPreferredSize(new java.awt.Dimension(106, 66));
        jTextAreaDescription.setLineWrap(true);
        jTextAreaDescription.setWrapStyleWord(true);
        jScrollPaneDescription.setViewportView(jTextAreaDescription);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jScrollPaneDescription, gridBagConstraints);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelDescription;
    private javax.swing.JLabel jLabelIcon;
    private javax.swing.JLabel jLabelName;
    private javax.swing.JScrollPane jScrollPaneDescription;
    private javax.swing.JTextArea jTextAreaDescription;
    private javax.swing.JTextField jTextFieldName;
    // End of variables declaration//GEN-END:variables
    
}
